var xhr;
function init(result){
	document.getElementById('gotoindex').scrollIntoView();
	if(result != 1){ // 判断是否是被拦截的
		$( "#logindialog" ).dialog( "open" );
	}
}

function validation(){
	alert("validation");
	return true;
}
function loginAjax(){
	var userName = document.getElementById("username").value;
	var password = document.getElementById("pwd").value;
	var json_url = "json/systemManager-login.html?userName="+userName+"&password="+password;
	xhr = null;
	xhr = connectXHR(json_url, loginResult);
}
function loginResult(){
	if(xhr == null){return;}
	
	if(xhr.readyState == 4 && xhr.status == 200) {
		var data = eval('(' + xhr.responseText + ')');
		var result = data;
		if(result == 3){//系统不存在此用户名
			jQuery('#username').validationEngine('showPrompt', '系统不存在此用户', 'error', true);
		}else if(result == 2){//密码错误
			jQuery('#pwd').validationEngine('showPrompt', '密码错误', 'error', true);
		}else if(result == 1){//登录成功
			document.getElementById("loginform").submit();
		}
	}
}
function enterKey(event){
	if(event.keyCode == 13){
		loginAjax();
	}
}